package org.jeecg.modules.demo.applet.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.demo.applet.service.IAppletService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * xh 小程序接口
 */
@SuppressWarnings("unchecked")
@Api(tags = "xh 小程序接口")
@RestController
@RequestMapping("/applet")
@Slf4j
public class AppletController extends JeecgController<Map<String, Object>, IAppletService> {
//
//    @Autowired
//    private IAppletService appletService;
//    @Autowired
//    private CashierService cashierService;
//    @Autowired
//    private IBaseMemberVipService baseMemberVipService;
//    @Autowired
//    private IVipCardCouponService vipCardCouponService;
//    @Autowired
//    private IShareholderVipCardService shareholderVipCardService;
//    @Autowired
//    private IBaseMemberVipCouponService baseMemberVipCouponService;
//    @Autowired
//    private ISysUserService sysUserService;
//    @Autowired
//    private RedisUtil redisUtil;
//    @Autowired
//    private IMemberManagementService memberManagementService;
//    @Autowired
//    private IStoreInfoService storeInfoService;
//    @Autowired
//    private IAllVipcardService allVipcardService;
//    @Autowired
//    private IBaseOrderService baseOrderService;
//    /**
//     * 查询自己可用贵宾卡
//     * applet/getMemberVip get请求
//     * @param memberId 会员id
//     * @param storeId  店铺id
//     * @param pageNo 分页页数
//     * @param pageSize 一页展示多少数据
//     */
//    @AutoLog(value = "xh小程序-查询自己可用贵宾卡")
//    @ApiOperation(value = "xh小程序-查询自己可用贵宾卡", notes = "xh小程序-查询自己可用贵宾卡")
//    @GetMapping(value = "/getMemberVip")
//    public Result<?> getMemberVip(String memberId,String storeId,
//                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
//                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
//        QueryWrapper<BaseMemberVip> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("member_id", memberId);
//        queryWrapper.eq("status", "1");
//        queryWrapper.eq("type", "2");
//        Page<BaseMemberVip> page = new Page<>(pageNo, pageSize);
//        IPage<BaseMemberVip> pageList = baseMemberVipService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//    /**
//     * 查询可赠送的优惠券
//     * applet/getMemberShareVip get请求
//     * @param memberId 会员id
//     * @param storeId  店铺id
//     * @param pageNo 分页页数
//     * @param pageSize 一页展示多少数据
//     */
//    @AutoLog(value = "xh小程序-查询可赠送的优惠券")
//    @ApiOperation(value = "xh小程序-查询可赠送的优惠券", notes = "xh小程序-查询可赠送的优惠券")
//    @GetMapping(value = "/getMemberShareVip")
//    public Result<?> getMemberShareVip(String memberId,String storeId,
//                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
//                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
//        QueryWrapper<BaseMemberVip> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("member_id", memberId);
//        queryWrapper.eq("status", "1");
//        queryWrapper.eq("type", "3");
//        Page<BaseMemberVip> page = new Page<>(pageNo, pageSize);
//        IPage<BaseMemberVip> pageList = baseMemberVipService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//
//    /**
//     * 查询股东拓客卡
//     * applet/getStockVip  get请求
//     * @param stockId 股东id 不会会员的id
//     * @param storeId  店铺id
//     * @param pageNo   分页页数
//     * @param pageSize 一页展示多少数据
//     */
//    @AutoLog(value = "xh小程序-查询股东拓客卡")
//    @ApiOperation(value = "xh小程序-查询股东拓客卡", notes = "xh小程序-查询股东拓客卡")
//    @GetMapping(value = "/getStockVip")
//    public Result<?> getStockVip(String stockId,String storeId,
//                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
//                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
//        QueryWrapper<BaseMemberVip> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("member_id", stockId);
//        queryWrapper.eq("status", "2");
//        queryWrapper.eq("type", "3");
//        Page<BaseMemberVip> page = new Page<>(pageNo, pageSize);
//        IPage<BaseMemberVip> pageList = baseMemberVipService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//
//    /**
//     * 会员查看可领取的贵宾卡   applet/getMemberSendVip get请求
//     * @param memberId 会员id
//     * @param storeId  店铺id
//     * @param pageNo 分页页数
//     * @param pageSize 一页展示多少数据
//     */
//    @AutoLog(value = "全部贵宾卡-会员查看可领取的贵宾卡")
//    @ApiOperation(value = "全部贵宾卡-会员查看可领取的贵宾卡", notes = "全部贵宾卡-会员查看可领取的贵宾卡")
//    @GetMapping(value = "/getMemberSendVip")
//    public Result<?> getMemberSendVip(String memberId,String storeId,
//                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
//                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
//
//        QueryWrapper<BaseMemberVip> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("member_id", memberId);
//        queryWrapper.eq("status", "1");
//        queryWrapper.eq("type", "1");
//        Page<BaseMemberVip> page = new Page<>(pageNo, pageSize);
//        IPage<BaseMemberVip> pageList = baseMemberVipService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//
//    /**
//     * 会员领取分享的优惠劵
//     * applet/receiveCoupon  get请求
//     * @param receiveId 收卡人ID
//     * @param vipId     贵宾卡ID
//     */
//    @AutoLog(value = "全部贵宾卡-会员领取分享的优惠劵")
//    @ApiOperation(value = "全部贵宾卡-会员领取分享的优惠劵", notes = "全部贵宾卡-会员领取分享的优惠劵")
//    @GetMapping(value = "/receiveCoupon")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    public Result<?> receiveCoupon(String receiveId, String vipId) {
//
//        BaseMemberVip baseMemberVip = baseMemberVipService.getById(vipId);
////        String type = baseMemberVip.getType();
////        int num = baseMemberVip.getNum();
////        if (num <= 0) {
////            return Result.error("此贵宾卡已被领取完！");
////        }
////        baseMemberVip.setNum(num - 1);
//        baseMemberVipService.updateById(baseMemberVip);
//
//        QueryWrapper<BaseMemberVip> queryVip = new QueryWrapper<>();
//        queryVip.eq("send_vip_id", baseMemberVip.getId());
//        queryVip.eq("member_id", receiveId);
//        BaseMemberVip receiveMemberVip = baseMemberVipService.getOne(queryVip);
//        if (receiveMemberVip != null) {
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            return Result.error("您已经领取了贵宾卡，不能重复领取！");
//        }
//
//        receiveMemberVip = new BaseMemberVip();
//        BeanUtils.copyProperties(baseMemberVip, receiveMemberVip);
//        receiveMemberVip.setMemberId(receiveId);
////        receiveMemberVip.setSendVipId(baseMemberVip.getId());
////        receiveMemberVip.setType("2");
//        receiveMemberVip.setId(null);
//        baseMemberVipService.save(receiveMemberVip);
//
//        QueryWrapper<VipCardCoupon> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("vip_id", baseMemberVip.getId());
//        List<VipCardCoupon> pageList = vipCardCouponService.list(queryWrapper);
//        for (VipCardCoupon bean : pageList) {
//            VipCardCoupon vipCardCoupon = new VipCardCoupon();
//            BeanUtils.copyProperties(bean, vipCardCoupon);
//            vipCardCoupon.setVipId(receiveMemberVip.getId());
//            vipCardCouponService.save(vipCardCoupon);
//        }
//
////        //分享的卡 不更新发卡记录表 如果是股东拓客卡 要更新股东发卡记录
////        if (type.equals("2")) {
////            QueryWrapper<ShareholderVipCard> query = new QueryWrapper<>();
////            query.eq("vip_id", baseMemberVip.getId());
////            ShareholderVipCard shareholderVipCard = shareholderVipCardService.getOne(query);
////            int alreadyGet = ToolsUtils.getNumeric(shareholderVipCard.getAlreadyGet());
////            shareholderVipCard.setAlreadyGet(String.valueOf(alreadyGet + 1));
////            shareholderVipCardService.updateById(shareholderVipCard);
////        }
//
//        return Result.OK("领取成功！");
//    }
//
//    /**
//     * 领取贵宾卡
//     * applet/receiveCoupon post请求
//     * memberId 会员id
//     * storeId  店铺id
//     */
//    @AutoLog(value = "xh小程序-领取贵宾卡")
//    @ApiOperation(value = "xh小程序-领取贵宾卡", notes = "xh小程序-领取贵宾卡")
//    @PostMapping(value = "/receiveCoupon")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    public Result<?> receiveCoupon(@RequestBody Map<String, Object> map) {
//        String memberId = map.get("memberId") == null ? null : String.valueOf(map.get("memberId"));
//        String vipId = map.get("vipId") == null ? null : String.valueOf(map.get("vipId"));
//        if(StringUtils.isEmpty(memberId) || StringUtils.isEmpty(vipId)){
//            return Result.error("参数不全");
//        }
//
//        BaseMemberVip baseMemberVip = baseMemberVipService.getById(vipId);
////        String type = baseMemberVip.getType();
////        int num = baseMemberVip.getNum();
////        if (num <= 0) {
////            return Result.error("此贵宾卡已被领取完！");
////        }
////        baseMemberVip.setNum(num - 1);
//        baseMemberVipService.updateById(baseMemberVip);
//
//        QueryWrapper<BaseMemberVip> queryVip = new QueryWrapper<>();
//        queryVip.eq("send_vip_id", baseMemberVip.getId());
//        queryVip.eq("member_id", memberId);
//        BaseMemberVip receiveMemberVip = baseMemberVipService.getOne(queryVip);
//        if (receiveMemberVip != null) {
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            return Result.error("您已经领取了贵宾卡，不能重复领取！");
//        }
//
//        receiveMemberVip = new BaseMemberVip();
//        BeanUtils.copyProperties(baseMemberVip, receiveMemberVip);
//        receiveMemberVip.setMemberId(memberId);
////        receiveMemberVip.setSendVipId(baseMemberVip.getId());
////        receiveMemberVip.setType("2");
//        receiveMemberVip.setId(null);
//        baseMemberVipService.save(receiveMemberVip);
//
//        QueryWrapper<VipCardCoupon> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("vip_id", baseMemberVip.getId());
//        List<VipCardCoupon> pageList = vipCardCouponService.list(queryWrapper);
//        for (VipCardCoupon bean : pageList) {
//            VipCardCoupon vipCardCoupon = new VipCardCoupon();
//            BeanUtils.copyProperties(bean, vipCardCoupon);
//            vipCardCoupon.setVipId(receiveMemberVip.getId());
//            vipCardCouponService.save(vipCardCoupon);
//        }
//
////        //分享的卡 不更新发卡记录表 如果是股东拓客卡 要更新股东发卡记录
////        if (type.equals("2")) {
////            QueryWrapper<ShareholderVipCard> query = new QueryWrapper<>();
////            query.eq("vip_id", baseMemberVip.getId());
////            ShareholderVipCard shareholderVipCard = shareholderVipCardService.getOne(query);
////            int alreadyGet = ToolsUtils.getNumeric(shareholderVipCard.getAlreadyGet());
////            shareholderVipCard.setAlreadyGet(String.valueOf(alreadyGet + 1));
////            shareholderVipCardService.updateById(shareholderVipCard);
////        }
//
//        return Result.OK("领取成功！");
//    }
//
//    /**
//     * 会员领取新人卡
//     * applet/coupleCoupon  get请求
//     * @param memberId 会员ID
//     */
//    @AutoLog(value = "全部贵宾卡-会员领取新人卡")
//    @ApiOperation(value = "全部贵宾卡-会员领取新人卡", notes = "全部贵宾卡-会员领取新人卡")
//    @GetMapping(value = "/coupleCoupon")
//    @Transactional(rollbackFor = JeecgBootException.class)//
//    public Result<?> coupleCoupon(String memberId) {
//        QueryWrapper<AllVipcard> query = new QueryWrapper<>();
//        query.eq("card_type", "新人卡");
//        AllVipcard allVipcard = allVipcardService.getOne(query);
//
//        if (allVipcard == null) {
//            return Result.error("没有新人卡");
//        }
//        //把当前贵宾卡和会员卡状态 赋值到新的表
//        BaseMemberVip baseMemberVip = new BaseMemberVip();
//        BeanUtils.copyProperties(allVipcard, baseMemberVip);
//        baseMemberVip.setId(null);
////        baseMemberVip.setStatus("1");
////        baseMemberVip.setType("2");
//        baseMemberVip.setMemberId(memberId);
////        baseMemberVip.setNum(1);
//        baseMemberVipService.save(baseMemberVip);
//
//        QueryWrapper<VipCardCoupon> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("vip_id", allVipcard.getId());
//        List<VipCardCoupon> pageList = vipCardCouponService.list(queryWrapper);
//        for (VipCardCoupon bean : pageList) {
//            BaseMemberVipCoupon baseMemberVipCoupon = new BaseMemberVipCoupon();
//            BeanUtils.copyProperties(bean, baseMemberVipCoupon);
//            baseMemberVipCoupon.setId(null);
////            baseMemberVipCoupon.setVipId(baseMemberVip.getId());
//            baseMemberVipCouponService.save(baseMemberVipCoupon);
//        }
//        return Result.OK("领取成功");
//    }
//
//    /**
//     * 生成二维码
//     * applet/qrCode
//     * @param codeContent 内容 直接把 贵宾卡 ID 内容放进来
//     * @param response
//     */
//    @GetMapping("qrCode")
//    public void getQRCode(String codeContent, HttpServletResponse response) {
//        System.out.println("codeContent=" + codeContent);
//        if(StringUtils.isEmpty(codeContent)){
//            return;
//        }
//        try {
//            /*
//             * 调用工具类生成二维码并输出到输出流中
//             */
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String time = simpleDateFormat.format(new Date());
//            QRCodeUtil.createCodeToOutputStream(codeContent +","+ time, response.getOutputStream());
//            log.info("成功生成二维码!");
//        } catch (IOException e) {
//            log.error("发生错误， 错误信息是：{}！", e.getMessage());
//        }
//    }
//
//
//    /**
//     * 会员扫码领取优惠劵
//     * applet/memberScanCode
//     * 系统要生成一个二维码 里面有 time(yyyy-MM-dd HH:mm:ss) 和 vipId 两个属性参数  获取后调用此接口  time为当前时间 超过当前时间10分钟后失效
//     * @param memberId 会员ID
//     * @param vipId  贵宾卡ID
//     * @param time   二维码时间
//     */
//    @AutoLog(value = "全部贵宾卡-会员扫码领取优惠劵")
//    @ApiOperation(value = "全部贵宾卡-会员扫码领取优惠劵", notes = "全部贵宾卡-会员扫码领取优惠劵")
//    @GetMapping(value = "/memberScanCode")
//    @Transactional(rollbackFor = JeecgBootException.class)//事物
//    public Result<?> memberScanCode(String memberId, String vipId, String time) throws ParseException {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date nowDate = simpleDateFormat.parse(time);
//        long nd = 1000 * 24 * 60 * 60;//每天毫秒数
//        long nh = 1000 * 60 * 60;//每小时毫秒数
//        long nm = 1000 * 60;//每分钟毫秒数
//        Date endDate = new Date();
//        long diff = endDate.getTime() - nowDate.getTime(); //获得两个时间的毫秒时间差异
//        long min = diff % nd % nh / nm;  // 计算差多少分钟
//        if (min > 10) {
//            return Result.error("二维码超过了10分钟 已失效");
//        }
//
//        AllVipcard allVipcard = allVipcardService.getById(vipId);
//        //把当前贵宾卡和会员卡状态 赋值到新的表
//        BaseMemberVip baseMemberVip = new BaseMemberVip();
//        BeanUtils.copyProperties(allVipcard, baseMemberVip);
//        baseMemberVip.setId(null);
////        baseMemberVip.setStatus("1");
////        baseMemberVip.setType("2");
//        baseMemberVip.setMemberId(memberId);
////        baseMemberVip.setNum(1);
//        baseMemberVipService.save(baseMemberVip);
//
//        QueryWrapper<VipCardCoupon> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("vip_id", vipId);
//        List<VipCardCoupon> pageList = vipCardCouponService.list(queryWrapper);
//        for (VipCardCoupon bean : pageList) {
//            BaseMemberVipCoupon baseMemberVipCoupon = new BaseMemberVipCoupon();
//            BeanUtils.copyProperties(bean, baseMemberVipCoupon);
//            baseMemberVipCoupon.setId(null);
////            baseMemberVipCoupon.setVipId(baseMemberVip.getId());
//            baseMemberVipCouponService.save(baseMemberVipCoupon);
//        }
//
//        //会员扫码 暂不生成下发记录
//        return Result.OK("领取成功");
//    }
//
//
//    /**
//     * 查询某贵宾卡下的优惠券列表
//     * applet/getReceiveCoupon  get请求
//     * @param vipId 贵宾卡ID
//     * @param pageNo   分页页数
//     * @param pageSize 一页展示多少数据
//     */
//    @AutoLog(value = "xh小程序-查询某贵宾卡下的优惠券列表")
//    @ApiOperation(value = "xh小程序-查询某贵宾卡下的优惠券列表", notes = "xh小程序-查询某贵宾卡下的优惠券列表")
//    @GetMapping(value = "/getReceiveCoupon")
//    public Result<?> getReceiveCoupon(String vipId,
//                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
//                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
//        QueryWrapper<BaseMemberVipCoupon> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("vip_id", vipId);
//        Page<BaseMemberVipCoupon> page = new Page<>(pageNo, pageSize);
//        IPage<BaseMemberVipCoupon> pageList = baseMemberVipCouponService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//
//    /**
//     * 获取优惠劵列表 applet/listCoupon get请求
//     * 参数：storeId, memberId
//     */
//    @AutoLog(value = "xh小程序-获取全部优惠劵")
//    @ApiOperation(value = "xh小程序-获取全部优惠劵", notes = "xh小程序-获取全部优惠劵")
//    @GetMapping("/listCoupon")
//    public Result<?> listCoupon(String memberId, String storeId) {
////        return cashierService.listCoupon(storeId, memberId);
//        return null;
//    }
//
//    /**
//     * 生成待付款订单 post 请求
//     * applet/getPreSaveOrder
//     * storeId  店铺id
//     * memberId 会员id
//     * useMemberDiscount 是否使用会员折扣
//     * memberDiscount  会员折扣金额
//     * remark  买家留言或备注
//     * totalAmount  总金额
//     * totalDiscountAmount 优惠金额
//     * realAmount  实际支付金额
//     * couponIds[]     使用的优惠劵 id列表
//     * orderId 订单ID
//     *
//     * commodityList[] 商品列表
//     * 商品列表 参数
//     * id 商品或项目id
//     * type  1=商品 2=项目
//     * count  购买数量
//     * totalPrice 商品总价格
//     * discountAmount  商品的优惠金额 （根据优惠劵和折扣等算法 要算出每件商品的优惠金额）
//     */
//    @AutoLog(value = "xh小程序-待付款")
//    @ApiOperation(value = "xh小程序-待付款", notes = "xh小程序-待付款")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    @PostMapping("/getPreSaveOrder")
//    public Result<?> preSaveOrder(@RequestBody Map<String, Object> map) {
//        String memberId = map.get("memberId") == null ? null : String.valueOf(map.get("memberId"));
//        String storeId = map.get("storeId") == null ? null : String.valueOf(map.get("storeId"));
//        String useMemberDiscount = map.get("useMemberDiscount") == null ? null : String.valueOf(map.get("useMemberDiscount"));
//        String totalAmount = map.get("totalAmount") == null ? null : String.valueOf(map.get("totalAmount"));
//        String totalDiscountAmount = map.get("totalDiscountAmount") == null ? null : String.valueOf(map.get("totalDiscountAmount"));
//        String realAmount = map.get("realAmount") == null ? null : String.valueOf(map.get("realAmount"));
//        List<Map<String, Object>> commodityList = (List<Map<String, Object>>) map.get("commodityList");
//        String patternPayment = map.get("patternPayment") == null ? "" : String.valueOf(map.get("patternPayment"));
//        if (StringUtils.isEmpty(storeId)
//                || StringUtils.isEmpty(memberId)
//                || StringUtils.isEmpty(useMemberDiscount)
//                || CollectionUtils.isEmpty(commodityList)
//                || StringUtils.isEmpty(totalAmount)
//                || StringUtils.isEmpty(totalDiscountAmount)
//                || StringUtils.isEmpty(realAmount)
//                || StringUtils.isEmpty(patternPayment)) {
//            return Result.error("参数不全");
//        }
//
//        return appletService.getPreSaveOrder(map);
//    }
//
//    /**
//     *  待付款订单 付款 post 请求
//     *  applet/payOrder
//     *  orderId  待付款订单ID  调待付款接口的时候会给你返订单的所有信息 里面的ID 就是订单ID
//     *  storeId
//     *  payCode  支付流水号
//     *  patternPayment  支付类型  03=微信支付 04=支付宝支付 05=会员余额支付 06=股本余额支付
//     *  balanceAmount   会员抵扣金额（联合支付 比如消费100 微信支付20 使用会员余额支付80  支付类型还是微信）
//     *  stockBalanceAmount  股东抵扣金额 和会员抵扣金额逻辑一样（股东有最低限额 可用余额 = 股本余额 - 最低限额）
//     */
//    @AutoLog(value = "xh小程序-付款")
//    @ApiOperation(value = "xh小程序-付款", notes = "xh小程序-付款")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    @PostMapping("/payOrder")
//    public Result<?> payOrder(@RequestBody Map<String, Object> map){
//        String orderId = map.get("orderId") == null ? null : String.valueOf(map.get("orderId"));
//        String storeId = map.get("storeId") == null ? null : String.valueOf(map.get("storeId"));
//        //String payCode = map.get("payCode") == null ? null : String.valueOf(map.get("payCode"));
//
//        if (StringUtils.isEmpty(orderId) || StringUtils.isEmpty(storeId)){
//            return Result.error("参数不全");
//        }
//        BaseOrder order = baseOrderService.getById(orderId);
//        if(order == null){
//            return Result.error("订单异常");
//        }
////        String jsonStr = order.getJsonStr();
////        JSONObject json = JSONObject.parseObject(jsonStr);
////        map.put("memberId",  json.get("memberId"));
////        map.put("useMemberDiscount", json.get("useMemberDiscount"));
////        map.put("memberDiscount", json.get("memberDiscount"));
////        map.put("remark", json.get("remark"));
////        map.put("totalAmount", json.get("totalAmount"));
////        map.put("totalDiscountAmount", json.get("totalDiscountAmount"));
////        map.put("realAmount", json.get("realAmount"));
////        //map.put("patternPayment", json.get("patternPayment"));
////        //map.put("balanceAmount", json.get("balanceAmount"));
////        //map.put("stockBalanceAmount", json.get("stockBalanceAmount"));
////        map.put("couponIds", json.get("couponIds"));
////        map.put("commodityList",  json.get("commodityList"));
////        map.put("orderId", orderId);
//        return appletService.saveOrder(map);
//    }
//
//    /**
//     * 支付 post 请求
//     * applet/saveOrder
//     * storeId  店铺id
//     * memberId 会员id
//     * useMemberDiscount 是否使用会员折扣 0不使用,1使用
//     * memberDiscount  会员折扣金额
//     * remark  买家留言或备注
//     * totalAmount  总金额
//     * totalDiscountAmount 优惠金额
//     * realAmount  实际支付金额
//     * patternPayment  支付类型  03=微信支付 04=支付宝支付 05=会员余额支付 06=股本余额支付
//     * balanceAmount   会员抵扣金额（联合支付 比如消费100 微信支付20 使用会员余额支付80  支付类型还是微信）
//     * stockBalanceAmount  股东抵扣金额 和会员抵扣金额逻辑一样（股东有最低限额 可用余额 = 股本余额 - 最低限额）
//     * couponIds[]     使用的优惠劵 id列表
//     *
//     * commodityList[] 商品列表
//     * 商品列表 参数
//     * id 商品或项目id
//     * type  1=商品 2=项目
//     * count  购买数量
//     * totalPrice 商品总价格
//     * discountAmount  商品的优惠金额 （根据优惠劵和折扣等算法 要算出每件商品的优惠金额）
//     *
//     */
//    @AutoLog(value = "xh小程序-支付")
//    @ApiOperation(value = "xh小程序-支付", notes = "xh小程序-支付")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    @PostMapping("/saveOrder")
//    public Result<?> saveOrder(@RequestBody Map<String, Object> map) {
//
//        String memberId = map.get("memberId") == null ? null : String.valueOf(map.get("memberId"));
//        String storeId = map.get("storeId") == null ? null : String.valueOf(map.get("storeId"));
//        String useMemberDiscount = map.get("useMemberDiscount") == null ? null : String.valueOf(map.get("useMemberDiscount"));
//        String totalAmount = map.get("totalAmount") == null ? null : String.valueOf(map.get("totalAmount"));
//        String totalDiscountAmount = map.get("totalDiscountAmount") == null ? null : String.valueOf(map.get("totalDiscountAmount"));
//        String realAmount = map.get("realAmount") == null ? null : String.valueOf(map.get("realAmount"));
//        List<Map<String, Object>> commodityList = (List<Map<String, Object>>) map.get("commodityList");
//        String patternPayment = map.get("patternPayment") == null ? "" : String.valueOf(map.get("patternPayment"));
//        if (StringUtils.isEmpty(storeId)
//                || StringUtils.isEmpty(memberId)
//                || StringUtils.isEmpty(useMemberDiscount)
//                || CollectionUtils.isEmpty(commodityList)
//                || StringUtils.isEmpty(totalAmount)
//                || StringUtils.isEmpty(totalDiscountAmount)
//                || StringUtils.isEmpty(realAmount)
//                || StringUtils.isEmpty(patternPayment)) {
//            return Result.error("参数不全");
//        }
//
//        return appletService.saveOrder(map);
//    }
//
//
//    /**
//     * 手机号登录接口    applet/phoneLogin
//     * 上传参数  post请求 不需要验证token
//     * mobile 手机号    必传
//     * storeId 店铺id  必传
//     *
//     * 返回参数
//     * user 账号信息
//     * member 对应会员信息里面id就是其他接口所需要的 memberId
//     *
//     * 对应手机号 sys_user登录表 只有一个  但会员表对应的手机号是多个  根据不同的店铺进行区分
//     *
//     */
//    @AutoLog(value = "xh小程序-手机号登录")
//    @ApiOperation(value = "xh小程序-手机号登录", notes = "xh小程序-手机号登录")
//    @PostMapping("/phoneLogin")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
//        Result<JSONObject> result;
//        String phone = jsonObject.getString("mobile");
//        String storeId = jsonObject.getString("storeId");
//        //校验用户有效性
//        SysUser sysUser = sysUserService.getUserByPhone(phone);
//        result = sysUserService.checkUserIsEffective(sysUser);
//        if(!result.isSuccess()) {
//            return result;
//        }
//
//        QueryWrapper<MemberManagement> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("phone", phone);
//        MemberManagement memberManagement = memberManagementService.getOne(queryWrapper);
//        if(memberManagement==null){
//            result.error500("该用户不存在，请注册");
//            return result;
//        }
//        //用户信息
//        JSONObject obj = new JSONObject();
//        String syspassword = sysUser.getPassword();
//        String username = sysUser.getUsername();
//        String token = JwtUtil.sign(username, syspassword);
//        redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
//        redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
//
//        obj.put("token", token);
//        obj.put("user",sysUser);
//        obj.put("member",memberManagement);
//        result.setResult(obj);
//        result.success("登录成功");
//        return result;
//    }
//
//    /**
//     * 手机号注册  applet/register
//     * 上传参数  post请求 不需要验证token
//     * mobile 手机号    必传
//     * password 密码   默认123456  非必须
//     * storeId 店铺id    必传
//     * nickName 昵称  默认空  非必须
//     * sex (01 男性 02 女性 03保密  默认空)  非必须
//     * memberType （两种  股东会员 店铺会员 纯文本提交 默认股东会员）  非必须
//     */
//    @AutoLog(value = "xh小程序-手机号注册")
//    @ApiOperation(value = "xh小程序-手机号登录", notes = "xh小程序-手机号登录")
//    @PostMapping("/register")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    public Result<?> register(@RequestBody JSONObject jsonObject) {
//        String phone = jsonObject.getString("mobile");
//        String storeId = jsonObject.getString("storeId");
//        String password = jsonObject.getString("password") == null?"123456":jsonObject.getString("password");
//        String nickName = jsonObject.getString("nickName") == null?"":jsonObject.getString("nickName");
//        String sex = jsonObject.getString("sex") == null?"":jsonObject.getString("sex");
//        String memberType = jsonObject.getString("memberType") == null?"股东会员":jsonObject.getString("memberType");
//
//        SysUser sysUser1 = sysUserService.getUserByPhone(phone);
//        if (sysUser1 != null) {
//            return Result.error("该手机号已注册");
//        }
//
//        QueryWrapper<MemberManagement> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("phone", phone);
//        MemberManagement memberManagement = memberManagementService.getOne(queryWrapper);
//        if(memberManagement!=null){
//            return Result.error("该手机号已注册");
//        }else {
//            memberManagement = new MemberManagement();
//        }
//
//
//        SysUser user = new SysUser();
//        user.setCreateTime(new Date());//设置创建时间
//        user.setUsername(phone);
//        user.setPassword(password);
//        user.setRealname(memberManagement.getName());
//        user.setStoreId(storeId);
//        String salt = oConvertUtils.randomGen(8);
//        user.setSalt(salt);
//        String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
//        user.setPassword(passwordEncode);
//        user.setStatus(1);
//        user.setPhone(phone);
//        user.setDelFlag(CommonConstant.DEL_FLAG_0);
//        //生成会员账号
//        sysUserService.saveUser(user, "1484029312870592514", "");
//
//        StoreInfo storeInfo = storeInfoService.getById(storeId);
//        memberManagement.setBelongStore(storeInfo.getStoreName());
//        memberManagement.setStoreId(storeId);
//        memberManagement.setPhone(phone);
//        memberManagement.setNickName(nickName);
//        memberManagement.setSex(sex);
//        memberManagement.setStatus("2");
//        memberManagement.setMemberType(memberType);
//        memberManagementService.save(memberManagement);
//        return Result.OK("注册成功");
//    }
//
//    /**
//     * 修改手机号  applet/changMobile
//     * 上传参数   post请求
//     * mobile 修改之前手机号           必传
//     * changMobile 修改之后手机号      必传
//     * storeId 店铺id                必传
//     */
//    @AutoLog(value = "xh小程序-手机号注册")
//    @ApiOperation(value = "xh小程序-手机号登录", notes = "xh小程序-手机号登录")
//    @PostMapping("/changMobile")
//    @Transactional(rollbackFor = JeecgBootException.class)
//    public Result<?> changMobile(@RequestBody JSONObject jsonObject) {
//        String phone = jsonObject.getString("mobile");
//        String changMobile = jsonObject.getString("changMobile");
//        String storeId = jsonObject.getString("storeId");
//        //校验用户有效性
//        SysUser sysUser = sysUserService.getUserByPhone(phone);
//        Result<JSONObject> result = sysUserService.checkUserIsEffective(sysUser);
//        if(!result.isSuccess()) {
//            return result;
//        }
//
//        QueryWrapper<MemberManagement> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("store_id", storeId);
//        queryWrapper.eq("phone", phone);
//        MemberManagement memberManagement = memberManagementService.getOne(queryWrapper);
//        if(memberManagement==null){
//            return Result.error("该手机号未注册");
//        }
//
//        QueryWrapper<MemberManagement> queryWrapper2 = new QueryWrapper<>();
//        queryWrapper2.eq("store_id", storeId);
//        queryWrapper2.eq("phone", changMobile);
//        MemberManagement memberManagement2 = memberManagementService.getOne(queryWrapper2);
//        if(memberManagement2!=null){
//            return Result.error("更改后的手机号 在该店铺已存在");
//        }
//
//        memberManagement.setPhone(changMobile);
//        memberManagementService.updateById(memberManagement);
//
//        LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
//        query.eq(SysUser::getUsername, changMobile);
//        SysUser userv = sysUserService.getOne(query);
//        if (userv == null) {
//            SysUser user = new SysUser();
//            user.setCreateTime(new Date());
//            user.setUsername(changMobile);
//            user.setRealname(memberManagement.getName());
//            user.setStoreId(storeId);
//            String salt = oConvertUtils.randomGen(8);
//            user.setSalt(salt);
//            //String password = PasswordUtil.decrypt(sysUser.getPassword(),sysUser.getPassword(),sysUser.getSalt());
//            String passwordEncode = PasswordUtil.encrypt(changMobile, "123456", salt);
//            user.setPassword(passwordEncode);
//            user.setStatus(1);
//            user.setPhone(changMobile);
//            user.setDelFlag(CommonConstant.DEL_FLAG_0);
//            //生成会员账号
//            sysUserService.saveUser(user, "1484029312870592514", "");
//        }
//        return Result.OK("修改成功");
//    }
//
//    /**
//     * 会员详情（用会员id和会员类型查详情，返回会员属性以及会员折扣）
//     * 参数：storeId, id
//     */
//    @PostMapping("/getMember")
//    public Result<?> getMember(@RequestBody Map<String, Object> map, HttpServletRequest req) {
//        String storeId = map.get("storeId") == null ? null : String.valueOf(map.get("storeId"));
//        String id = map.get("memberId") == null ? null : String.valueOf(map.get("memberId"));
//        if (StringUtils.isEmpty(storeId) || StringUtils.isEmpty(id)) {
//            return Result.error("参数不全");
//        }
//        map.put("id",id);
//        return Result.OK(cashierService.getMember(map));
//    }
}
